export default {
  data() {
    return {
      id: '',
      pageIndex: 1,
      list: [],
      loadText: [
        'loadmore',
        'loading',
        'nomore'
      ],
      loadIndex: 0,
      totalpage: 0
    }
  },

  onLoad(options) {
    console.log(options)
    this.id = options.id
    this.GetBofferList()
  },
  onReachBottom: function() {
    if (this.totalpage === 0) {
      this.pageIndex = 1
      this.GetBofferList()
    } else {
      let zs = Math.ceil(this.totalpage / 10) //总共多少页
      // 买车订单
      if (zs > this.pageIndex) {
        this.pageIndex++
        this.GetBofferList()
      } else {
        this.loadIndex = 2
      }
    }
  },
  methods: {
    async GetBofferList() {

      try {
        let data = {
          'pageIndex': this.pageIndex,
          'pageSize': 10,
          'id': this.id,
          'distanceSorting': 0,
          'priceSorting': 0,
          'lat': 0,
          'lon': 0
        }
        this.loadIndex = 1
        const res = await this.$api.findCar.GetBofferList(data)
        this.list = this.list.concat(res.data.list)
        this.totalpage = res.data.total
        if (this.totalpage / 10 > this.pageIndex) {
          this.loadIndex = 0
        } else {
          this.loadIndex = 2
        }
        console.log(res)
      } catch (e) {
        //TODO handle the exception
      }

    },
    returnTime(it){
      if(it){
        return it.split('T')[0] +' '+ it.split('T')[1]
      }
    },
  }
}
